<template>
  <section>
    <div class="components" @click="showDetail(msg.msgid)">
      <div class="headImg">
        <img :src="msg.avatar"/>
      </div>
      <div class="content">
        <div class="nickName">{{ msg.title }}</div>
        <div class="contents">{{ msg.description }}</div>
      </div>
      <div class="time">{{ msg.time.toString().split('T').join(' ').split('.').slice(0, 1).join('') }}</div>
    </div>
    <van-popup style="text-align: left;padding: 8px 6px;box-sizing: border-box" v-model="show"
               position="bottom" round closeable :style="{ width:'100%',height: '80%' }">
      <div style="width: 100%;height: 100%" v-html="msg.html"></div>
    </van-popup>
  </section>
</template>

<script>
import { requestReadMsg } from '../../api/msg'

export default {
  name: 'MsgBar',
  props: {
    msg: {
      type: Object,
      default () {
        return {
          avatar: '',
          title: '',
          description: '',
          time: '2022-04-14T23:41:09.268Z',
          html: ''
        }
      }
    },
    isRead: {
      type: Boolean,
      default () {
        return false
      }
    }
  },
  data () {
    return {
      show: false
    }
  },
  methods: {
    showDetail (msgid) {
      this.show = true
      console.log(this.isRead)
      if (!this.isRead) {
        requestReadMsg(msgid).then(res => {
          console.log(res)
        })
      }
    }
  }
}
</script>

<style scoped>
.components {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px;
  text-align: left;
  background: #fff;
  border-bottom: 1px solid #eee;
}

.components .headImg {
  width: 50px;
  height: 50px;
  overflow: hidden;
  /* margin-left: 10rpx; */
  margin-right: 10px;
  border-radius: 50%;
}

.headImg > image {
  width: 100%;
  height: 100%;
}

.content {
  flex-grow: 1;
}

.content .nickName {
  color: #222;
  font-size: 16px;
}

.content .contents {
  color: #aaa;
  font-size: 12.5px;
  margin-top: 5px;
}

.redPoint {
  width: 10px;
  height: 10px;
  background: red;
  border-radius: 50%;
  margin-top: 10px;
  margin-right: 8px;
}

.time {
  position: absolute;
  font-size: 12px;
  color: #aaa;
  top: 18px;
  right: 15px;
}
</style>
